#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import subprocess as sp


def myprint(obj, end='\n'):
    sys.stdout.write(str(obj) + end)


def main():
    cmd = 'ping localhost'
    p = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
    for line in iter(p.stdout.readline, ""):
        if line==b'':
            break
        myprint(line.strip().decode('gbk'))

if __name__ == '__main__':
    main()
    myprint('done')
